home *** CD-ROM | disk | FTP | other *** search
/ PC Player 2004 May / pc player 2004-05.iso / Demos / FarCry / Data1.cab / _FA74B1033CF245E9A75D32B1B953457D < prev    next >
Encoding:
Text File  |  2004-01-06  |  13.0 KB  |  518 lines

  1. --
  2.  
  3. -- HeliStatic
  4. -------------------------------------------------------------------------------------------------------------
  5.  
  6.  
  7.  
  8.  
  9. HeliStatic = {
  10.     
  11.     temp_ModelName = "none",
  12.     
  13.     pathStep = 0,
  14.     dropState = 0,
  15.  
  16.     V22PhysParams = {
  17.         mass = 900,
  18.         height = .1,
  19.         eyeheight = .1,
  20.         sphereheight = .1,
  21.         radius = .5,
  22.         gravity = 0,
  23.         aircontrol = 1,    
  24.     },
  25.  
  26.  
  27.     damage = 0,
  28.     bExploded = 0,
  29.  
  30.     pieces = {},
  31.  
  32.     explosionImpulse = 10,
  33.  
  34.     Properties = {        
  35.  
  36.         fDmgScaleBullet = .1,
  37.         fDmgScaleExplosion = 1.7,
  38.         
  39.         bTrackable=1,
  40.  
  41.         max_health = 100,
  42.         bRigidBodyActive = 0,
  43.         Mass = 5000,
  44.         
  45.         fileModel = "objects/vehicles/troopgunship/troopgunship_inflight.cgf",        
  46.         
  47.         ExplosionParams = {
  48.             nDamage = 100,
  49.             fRadiusMin = 20.0, -- default 12
  50.             fRadiusMax = 20.5, -- default 70.5
  51.             fRadius = 20, -- default 30O
  52.             fImpulsivePressure = 100600, -- default 200
  53.         },
  54.  
  55.         sound_engine_file = "SOUNDS/Ambient/E3/hele/heleLP1.wav",
  56.     },
  57.     
  58.     DamageParticles1 = {
  59.         focus = 1.8, -- default 90
  60.         speed = 1.55, -- default 0.25
  61.         count = 1, -- default 1
  62.         size = 0.04, size_speed=0.1, -- default size = 0.04-- default size_speed = 0.03 
  63.         gravity={x=0.0,y=0.0,z=0.3}, -- default z= 0.3
  64.         rotation={x=0.0,y=0.0,z=1.75}, -- default z= 1.75
  65.         lifetime=2, -- default 2
  66.         tid = System:LoadTexture("textures/clouda.dds"),
  67.         frames=0,
  68.         color_based_blending = 0 -- default 0
  69.     },
  70.  
  71.     DamageParticles2 = {
  72.         focus = 1.8, -- default 1.8
  73.         speed = 0.6, -- default 1
  74.         count = 1, -- default 1
  75.         size = 0.3, size_speed=0.5, -- default size = 1.5-- default size_speed = 0.5 
  76.         gravity={x=0.3,y=0.0,z=0.3}, -- default z= 0.3
  77.         rotation={x=1.75,y=1,z=1.75}, -- default z= 1.75
  78.         lifetime=4, -- default 7
  79.         tid = System:LoadTexture("textures\\cloud_black1.dds"), 
  80.         frames=0,
  81.         color_based_blending = 0 -- default 0
  82.     },
  83.     
  84.     sound_engine = nil,
  85.  
  86. }
  87.  
  88.  
  89. ----------------------------------------------------------------------------------------------------------------------------
  90. --
  91. --
  92. ----------------------------------------------------------------------------------------------------------------------------
  93. --
  94. --
  95.  
  96. HeliStatic.Client = {
  97.     OnInit = function(self)
  98.         System:Log("Client HeliStatic onInit");
  99.         self:InitClient();
  100.     end,
  101.     OnContact = function(self,player)
  102.          self:OnContactClient(player);
  103.     end,
  104. --    OnEvent = function (self, id, params)
  105. --        self:OnEventClient( id, params);
  106. --    end,
  107.     OnUpdate = function(self,dt)
  108. --System.Log("V22 Client Update ");
  109. --        self:OnUpdate(dt);
  110.         self:UpdateClient(dt);
  111. --        self:UpdateCommon();
  112.     end
  113. }
  114.  
  115.  
  116. ------------------------------------------------------
  117. --
  118. --
  119. HeliStatic.Server = {
  120.     OnInit = function(self)
  121.         System:Log("Server HeliStatic onInit");    
  122.         self:InitServer();
  123.     end,
  124.     OnContact = function(self,player)
  125.          self:OnContactServer(player);
  126.     end,
  127.     OnEvent = function (self, id, params)
  128.         self:OnEventServer( id, params);
  129.     end,
  130.     OnShutDown = function (self)
  131.         self:OnShutDownServer(self);
  132.     end,
  133.     OnUpdate = function(self,dt)
  134. --System.Log("V22 Server Update ");    
  135. --        self:OnUpdate(dt);
  136.         self:UpdateServer(dt);
  137. --         self:UpdateCommon();
  138.     end,
  139.     OnDamage = function (self, hit)
  140.  
  141.         self:OnDamageServer( hit );
  142.     end,
  143.  
  144. }
  145.  
  146.  
  147. ----------------------------------------------------------------------------------------------------------------------------
  148. --
  149. --
  150. function HeliStatic:OnReset()
  151.  
  152.  
  153.     self.damage = 0;
  154.     self.sound_engine = Sound:Load3DSound(self.Properties.sound_engine_file, bor(SOUND_OUTDOOR,SOUND_UNSCALABLE),255,1,100);
  155.  
  156. end
  157.  
  158.  
  159. ----------------------------------------------------------------------------------------------------------------------------
  160. --
  161. --
  162. function HeliStatic:OnPropertyChange()
  163.  
  164.     self:OnReset();
  165.  
  166.     self:LoadModel();
  167.         
  168.     Sound:SetSoundLoop(self.sound_engine, 1);
  169.  
  170. end
  171.  
  172.  
  173. ----------------------------------------------------------------------------------------------------------------------------
  174. --
  175. --
  176. function HeliStatic:LoadModel()
  177.  
  178. System:Log( "loading HeliStatic "..self.Properties.fileModel );
  179.  
  180. --    if(self.IsPhisicalized == 0) then
  181.     if( self.temp_ModelName ~= self.Properties.fileModel ) then
  182. --        self:LoadObjectPiece(self.Properties.fileModel, -1 );
  183.         self:LoadObject( self.Properties.fileModel, 0,1 );        
  184.         
  185. --        self:DrawObject(0,1);
  186. --        self:CreateLivingEntity(self.V22PhysParams);        
  187.         
  188.         if (self.Properties.bRigidBodyActive == 1) then
  189.             self:CreateRigidBody( 1000,5000,0 );
  190. --            self:CreateRigidBody( self.Properties.Density,self.Properties.Mass,0 );            
  191.         else
  192.             self:CreateStaticEntity( 5000, 0 );
  193.             self:EnablePhysics( 1 );
  194.             self:DrawObject( 0, 1 );
  195.             
  196. --            self:CreateStaticEntity( self.Properties.Mass, 0 );            
  197.         end
  198.  
  199.         self.temp_ModelName = self.Properties.fileModel;
  200.  
  201.         --    load parts for explosion
  202.         local idx=1;
  203.         local    loaded=1;
  204.         while loaded==1 do
  205.             local piece=Server:SpawnEntity("Piece");
  206.             if(piece)then
  207.                 
  208. System:Log( "loading Piece #"..idx );                
  209.                 
  210.                 self.pieces[idx] = piece;
  211.                 loaded = self.pieces[idx].Load(self.pieces[idx],self.Properties.fileModel, idx );
  212.                 idx = idx + 1;
  213.             else
  214.                 break
  215.             end
  216.         end
  217.         self.pieces[idx-1] = nil;
  218.  
  219.         
  220.     end    
  221.  
  222. --    self:ActivatePhysics(0);
  223.  
  224.     self.temp_ModelName = self.Properties.fileModel;
  225. end
  226.  
  227. ----------------------------------------------------------------------------------------------------------------------------
  228. --
  229. --
  230. function HeliStatic:InitClient()
  231.  
  232.  
  233.     self:LoadModel();
  234.  
  235.     self:OnReset();
  236.     Sound:SetSoundLoop(self.sound_engine, 1);
  237.  
  238.     self.ExplosionSound=Sound:Load3DSound("sounds\\weapons\\explosions\\mbarrel.wav",0,0,7,100);
  239.  
  240. end
  241.  
  242. ----------------------------------------------------------------------------------------------------------------------------
  243. --
  244. --
  245. function HeliStatic:InitServer()
  246.  
  247.     self:OnReset();
  248.     
  249.     self:EnableUpdate(1);
  250.  
  251.     self:LoadModel();
  252.     
  253. --    self:NetPresent(1);
  254. end
  255.  
  256.  
  257. ----------------------------------------------------------------------------------------------------------------------------
  258. --
  259. --
  260.  
  261. ----------------------------------------------------------------------------------------------------------------------------
  262. --
  263. --
  264.  
  265. ----------------------------------------------------------------------------------------------------------------------------
  266. --
  267. --
  268. -------------------------------------------------------------------------------------------------------------
  269. --
  270. --
  271. function HeliStatic:OnContactServer( player )
  272.     
  273.     if(player.type ~= "Player" ) then
  274.         do return end
  275.     end
  276. end
  277.  
  278. -------------------------------------------------------------------------------------------------------------
  279. --
  280. --
  281. function HeliStatic:OnContactClient( player )
  282.     
  283.     if(player.type ~= "Player" ) then
  284.         do return end
  285.     end
  286.  
  287. end
  288.  
  289. -------------------------------------------------------------------------------------------------------------
  290. --
  291. --
  292. function HeliStatic:UpdateServer(dt)
  293.  
  294.  
  295. end
  296.  
  297.  
  298. -------------------------------------------------------------------------------------------------------------
  299. --
  300. function HeliStatic:UpdateClient(dt)
  301.  
  302.     --do force - grass/bushes deformation
  303.     local pos = self:GetPos();
  304.     pos.z=pos.z-5;
  305.     System:ApplyForceToEnvironment(pos, 50, 1);
  306.     
  307.     --do sounds
  308.     if( _localplayer and _localplayer.id and self.sound_engine ~= nil ) then
  309.         -- no hellicopter sound whein inside
  310.         if( System:IsPointIndoors(_localplayer:GetPos()) ) then
  311.             if (Sound:IsPlaying(self.sound_engine)) then
  312.                 Sound:StopSound(self.sound_engine);
  313.             end
  314.         else
  315.             Sound:SetSoundPosition(self.sound_engine, pos);
  316.             if (Sound:IsPlaying(self.sound_engine) == nil) then
  317.                 Sound:PlaySound(self.sound_engine);
  318.             end
  319.         end    
  320.     end    
  321.  
  322.     self:ExecuteDamageModel();
  323.  
  324. end
  325.  
  326. ----------------------------------------------------------------------------------------------------------------------------
  327. --
  328. function HeliStatic:OnDamageServer( hit )
  329.  
  330. --do return end
  331.  
  332.  
  333. System:LogToConsole( "Damage  "..hit.damage.." total "..self.damage );
  334.  
  335.     if( self.damage<0 ) then
  336.         do return end
  337.     end
  338.  
  339.     if( hit.explosion ) then
  340.         self.damage = self.damage + hit.damage*self.Properties.fDmgScaleExplosion;
  341.     else    
  342.         self.damage = self.damage + hit.damage*self.Properties.fDmgScaleBullet;
  343.     end    
  344.         
  345.     
  346.     
  347.     --self:SetDamage;
  348.  
  349. end
  350.  
  351.  
  352. ----------------------------------------------------------------------------------------------------------------------------
  353. --
  354. --
  355. function HeliStatic:OnShutDownServer()
  356.  
  357. System:LogToConsole( "HeliStatic OnShutDOWN ---------------------------" );
  358.  
  359.     
  360.     for idx,piece in self.pieces do
  361. --System:Log( " Piece #"..idx );
  362.         Server:RemoveEntity( piece.id );
  363.     end
  364.  
  365. end
  366.  
  367. ----------------------------------------------------------------------------------------------------------------------------
  368. --
  369. --
  370. function HeliStatic:OnSave(stm)
  371. end
  372.  
  373. ----------------------------------------------------------------------------------------------------------------------------
  374. --
  375. --
  376. function HeliStatic:OnLoad(stm)
  377. end
  378.  
  379. ----------------------------------------------------------------------------------------------------------------------------
  380. --
  381. --
  382. function HeliStatic:OnEventServer( id, params)
  383.  
  384.  
  385. --    if (id == ScriptEvent_Reset)
  386. --    then
  387. --    end
  388. end
  389.  
  390.  
  391. ----------------------------------------------------------------------------------------------------------------------------
  392. --
  393. --
  394. ----------------------------------------------------------------------------------------------------------------------------
  395. --
  396. --
  397.  
  398. function HeliStatic:OnWrite( stm )
  399.     
  400. end
  401.  
  402. ----------------------------------------------------------------------------------------------------------------------------
  403. --
  404. --
  405. function HeliStatic:OnRead( stm )
  406. end
  407.  
  408.  
  409. ----------------------------------------------------------------------------------------------------------------------------
  410. --
  411. --
  412. ----------------------------------------------------------------------------------------------------------------------------
  413. --
  414. --
  415.  
  416. --////////////////////////////////////////////////////////////////////////////////////////
  417. function HeliStatic:ExecuteDamageModel()
  418.  
  419.     if (self.damage>self.Properties.max_health*.2) then -- default 0.5                    
  420.  
  421.         -- middle damage
  422.         local vVec=self:GetHelperPos("vehicle_damage1",0); 
  423.         Particle:CreateParticle(vVec,{x=0, y=0, z=1},self.DamageParticles1); --vector(0,0,1) is up
  424.  
  425.         -- maximum damage
  426.         if (self.damage>self.Properties.max_health) then -- default 0.1
  427.             vVec=self:GetHelperPos("vehicle_damage2",0); 
  428.             Particle:CreateParticle(vVec,{x=0, y=0, z=1},self.DamageParticles2);
  429.             HeliStatic.BlowUp(self);
  430.         end
  431.     end
  432. end
  433.  
  434. --////////////////////////////////////////////////////////////////////////////////////////
  435. function HeliStatic:BlowUp()
  436.  
  437.  
  438.     if (self.bExploded==1) then
  439.         do return end
  440.     end
  441.  
  442.     System:Log("BLOW UP!");    
  443.  
  444.     local     explDir={x=0, y=0, z=1};
  445.     ExecuteMaterial(self:GetPos(),explDir,HeliExplosion,1);
  446.  
  447.     local ExplosionParams = {};
  448.     ExplosionParams.pos = self:GetPos();
  449.     ExplosionParams.damage= self.Properties.ExplosionParams.nDamage;
  450.     ExplosionParams.rmin = self.Properties.ExplosionParams.fRadiusMin;
  451.     ExplosionParams.rmax = self.Properties.ExplosionParams.fRadiusMax;
  452.     ExplosionParams.radius = self.Properties.ExplosionParams.fRadius;
  453.     ExplosionParams.impulsive_pressure = self.Properties.ExplosionParams.fImpulsivePressure;
  454.     ExplosionParams.shooter = self;
  455.     ExplosionParams.weapon = self.id;
  456.     Game:CreateExplosion( ExplosionParams );
  457.  
  458. --    ExplosionParams.pos = self:GetPos();
  459. --    ExplosionParams.pos.x=ExplosionParams.pos.x+2;
  460.     ExplosionParams.pos =    self:GetHelperPos("vehicle_damage2",0); 
  461.     Game:CreateExplosion( ExplosionParams );
  462.  
  463.     --play explosion sound
  464.     if (self.ExplosionSound ~= nil) then
  465.         --make sure to place the explosion sound at the correct position
  466.         Sound:SetSoundPosition(self.ExplosionSound,self:GetPos());
  467.         Sound:PlaySound(self.ExplosionSound);
  468.         --System:LogToConsole("playing explo sound");
  469.     end
  470.  
  471.     self:BreakOnPieces();
  472.  
  473. --    self.damage=0; 
  474.     self.bExploded=1;
  475.     --self.IsPhisicalized = 0; -- so that the next call to reset will reload the normal model
  476. end
  477.  
  478.  
  479.  
  480. --------------------------------------------------------------------------------------------------------------
  481.  
  482. function HeliStatic:BreakOnPieces()
  483.  
  484. local    pos=self:GetPos();
  485. local    angle=self:GetAngles();
  486.     self:DrawObject(0,0);    
  487. System:Log( " DoPiece ");    
  488. local    dir={x=0, y=0, z=1};
  489.     for idx,piece in self.pieces do
  490. System:Log( " Piece #"..idx );
  491.         piece:DrawObject(0,1);
  492.         piece:EnablePhysics(1);
  493.         piece:SetPos( pos );
  494.         piece:SetAngles( angle );        
  495.         dir.x= (2-random(0,4));
  496.         dir.y= (2-random(0,4));
  497.         dir.z= 2;
  498.         
  499. --        piece:AddImpulseObj(dir, self.explosionImpulse);
  500.         piece:Activate( piece );
  501.  
  502.     end
  503.  
  504.     if (self.sound_engine) then
  505.         Sound:StopSound(self.sound_engine);
  506.     end
  507.  
  508.     self:EnableUpdate( 0 );
  509. --    Server:RemoveEntity( self.id );    
  510.  
  511. end
  512.  
  513. --------------------------------------------------------------------------------------------------------------
  514. --------------------------------------------------------------------------------------------------------------
  515. --------------------------------------------------------------------------------------------------------------
  516. --
  517. --
  518.